/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

type OnSuccessFn = (data: string) => void;
type OnErrorFn = (errCode: number, errMsg: string) => void;
type OnSendProgressFn = (progress: number) => void;

export interface BaseCallback {
  OnSuccess?: OnSuccessFn;
  OnError?: OnErrorFn;
}

export interface SendMsgCallback {
  OnSuccess?: OnSuccessFn;
  OnError?: OnErrorFn;
  OnProgress?: OnSendProgressFn;
}

type OnConnectingFn = () => void;
type OnConnectSuccessFn = () => void;
type OnConnectFailedFn = (errCode: number, errMsg: string) => void;
type OnKickedOfflineFn = () => void;
type OnUserTokenExpiredFn = () => void;
type OnUserTokenInvalidFn = (errMsg: string) => void;

export interface ConnListener {
  OnConnecting?: OnConnectingFn;
  OnConnectSuccess?: OnConnectSuccessFn;
  OnConnectFailed?: OnConnectFailedFn;
  OnKickedOffline?: OnKickedOfflineFn;
  OnUserTokenExpired?: OnUserTokenExpiredFn;
  OnUserTokenInvalid?: OnUserTokenInvalidFn;
}

type OnJoinedGroupAddedFn = (groupInfo: string) => void;
type OnJoinedGroupDeletedFn = (groupInfo: string) => void;
type OnGroupMemberAddedFn = (groupMemberInfo: string) => void;
type OnGroupMemberDeletedFn = (groupMemberInfo: string) => void;
type OnGroupApplicationAddedFn = (groupApplication: string) => void;
type OnGroupApplicationDeletedFn = (groupApplication: string) => void;
type OnGroupInfoChangedFn = (groupInfo: string) => void;
type OnGroupDismissedFn = (groupInfo: string) => void;
type OnGroupMemberInfoChangedFn = (groupMemberInfo: string) => void;
type OnGroupApplicationAcceptedFn = (groupApplication: string) => void;
type OnGroupApplicationRejectedFn = (groupApplication: string) => void;

export interface GroupListener {
  OnJoinedGroupAdded?: OnJoinedGroupAddedFn;
  OnJoinedGroupDeleted?: OnJoinedGroupDeletedFn;
  OnGroupMemberAdded?: OnGroupMemberAddedFn;
  OnGroupMemberDeleted?: OnGroupMemberDeletedFn;
  OnGroupApplicationAdded?: OnGroupApplicationAddedFn;
  OnGroupApplicationDeleted?: OnGroupApplicationDeletedFn;
  OnGroupInfoChanged?: OnGroupInfoChangedFn;
  OnGroupDismissed?: OnGroupDismissedFn;
  OnGroupMemberInfoChanged?: OnGroupMemberInfoChangedFn;
  OnGroupApplicationAccepted?: OnGroupApplicationAcceptedFn;
  OnGroupApplicationRejected?: OnGroupApplicationRejectedFn;
}

type OnSyncServerStartFn = (reinstalled: number) => void;
type OnSyncServerFinishFn = (reinstalled: number) => void;
type OnSyncServerProgressFn = (progress: number) => void;
type OnSyncServerFailedFn = (reinstalled: number) => void;
type OnNewConversationFn = (conversationList: string) => void;
type OnConversationChangedFn = (conversationList: string) => void;
type OnTotalUnreadMessageCountChangedFn = (totalUnreadCount: number) => void;
type OnConversationUserInputStatusChangedFn = (change: string) => void;

export interface ConversationListener {
  OnSyncServerStart?: OnSyncServerStartFn;
  OnSyncServerFinish?: OnSyncServerFinishFn;
  OnSyncServerProgress?: OnSyncServerProgressFn;
  OnSyncServerFailed?: OnSyncServerFailedFn;
  OnNewConversation?: OnNewConversationFn;
  OnConversationChanged?: OnConversationChangedFn;
  OnTotalUnreadMessageCountChanged?: OnTotalUnreadMessageCountChangedFn;
  OnConversationUserInputStatusChanged?: OnConversationUserInputStatusChangedFn;
}

type OnRecvNewMessageFn = (message: string) => void;
type OnRecvC2CReadReceiptFn = (msgReceiptList: string) => void;
type OnNewRecvMessageRevokedFn = (messageRevoked: string) => void;
type OnRecvOfflineNewMessageFn = (message: string) => void;
type OnMsgDeletedFn = (message: string) => void;
type OnRecvOnlineOnlyMessageFn = (message: string) => void;

export interface AdvancedMsgListener {
  OnRecvNewMessage?: OnRecvNewMessageFn;
  OnRecvC2CReadReceipt?: OnRecvC2CReadReceiptFn;
  OnNewRecvMessageRevoked?: OnNewRecvMessageRevokedFn;
  OnRecvOfflineNewMessage?: OnRecvOfflineNewMessageFn;
  OnMsgDeleted?: OnMsgDeletedFn;
  OnRecvOnlineOnlyMessage?: OnRecvOnlineOnlyMessageFn;
}

type OnSelfInfoUpdatedFn = (userInfo: string) => void;
type OnUserStatusChangedFn = (userOnlineStatus: string) => void;

export interface UserListener {
  OnSelfInfoUpdated?: OnSelfInfoUpdatedFn;
  OnUserStatusChanged?: OnUserStatusChangedFn;
}

type OnFriendApplicationAddedFn = (friendApplication: string) => void;
type OnFriendApplicationDeletedFn = (friendApplication: string) => void;
type OnFriendApplicationAcceptedFn = (friendApplication: string) => void;
type OnFriendApplicationRejectedFn = (friendApplication: string) => void;
type OnFriendAddedFn = (friendInfo: string) => void;
type OnFriendDeletedFn = (friendInfo: string) => void;
type OnFriendInfoChangedFn = (friendInfo: string) => void;
type OnBlackAddedFn = (blackInfo: string) => void;
type OnBlackDeletedFn = (blackInfo: string) => void;

export interface FriendshipListener {
  OnFriendApplicationAdded?: OnFriendApplicationAddedFn;
  OnFriendApplicationDeleted?: OnFriendApplicationDeletedFn;
  OnFriendApplicationAccepted?: OnFriendApplicationAcceptedFn;
  OnFriendApplicationRejected?: OnFriendApplicationRejectedFn;
  OnFriendAdded?: OnFriendAddedFn;
  OnFriendDeleted?: OnFriendDeletedFn;
  OnFriendInfoChanged?: OnFriendInfoChangedFn;
  OnBlackAdded?: OnBlackAddedFn;
  OnBlackDeleted?: OnBlackDeletedFn;
}

type OnRecvCustomBusinessMessageFn = (businessMessage: string) => void;

export interface CustomBusinessListener {
  OnRecvCustomBusinessMessage?: OnRecvCustomBusinessMessageFn;
}

type OnMessageKvInfoChangedFn = (messageChangedList: string) => void;

export interface MessageKvInfoListener {
  OnMessageKvInfoChanged?: OnMessageKvInfoChangedFn;
}

type OnUploadLogProgressFn = (current: number, size: number) => void;

export interface UploadLogProgressCallback {
  OnProgress?: OnUploadLogProgressFn;
}

type OpenFn = (size: number) => void;
type PartSizeFn = (partSize: number, num: number) => void;
type HashPartProgressFn = (index: number, size: number, partHash: string) => void;
type HashPartCompleteFn = (partsHash: string, fileHash: string) => void;
type UploadIDFn = (uploadID: string) => void;
type UploadPartCompleteFn = (index: number, partSize: number, partHash: string) => void;
type UploadCompleteFn = (fileSize: number, streamSize: number, storageSize: number) => void;
type CompleteFn = (size: number, url: string, typ: number) => void;

export interface UploadFileCallback {
  Open?: OpenFn;
  PartSize?: PartSizeFn;
  HashPartProgress?: HashPartProgressFn;
  HashPartComplete?: HashPartCompleteFn;
  UploadID?: UploadIDFn;
  UploadPartComplete?: UploadPartCompleteFn;
  UploadComplete?: UploadCompleteFn;
  Complete?: CompleteFn;
}

export interface ErrMsg {
  code: number,
  errMsg: string
}

export const GetAllConversationList: (cb: BaseCallback, operationID: string) => void;
export const GetConversationListSplit: (cb: BaseCallback, operationID: string, offset: number, count: number) => void;
export const GetOneConversation: (cb: BaseCallback, operationID: string, sessionType: number, sourceID: string) => void;
export const GetMultipleConversation: (cb: BaseCallback, operationID: string, conversationIDList: string) => void;
export const SetConversation: (cb: BaseCallback, operationID: string, conversationID: string, req: string) => void;
export const HideConversation: (cb: BaseCallback, operationID: string, conversationID: string) => void;
export const SetConversationDraft: (cb: BaseCallback, operationID: string, conversationID: string, draftText: string) => void;
export const GetTotalUnreadMsgCount: (cb: BaseCallback, operationID: string) => void;
export const SendMessage: (cb: SendMsgCallback, operationID: string, message: string, recvID: string, groupID: string, offlinePushInfo: string, isOnlineOnly: number) => void;
export const SendMessageNotOss: (cb: SendMsgCallback, operationID: string, message: string, recvID: string, groupID: string, offlinePushInfo: string, isOnlineOnly: number) => void;
export const FindMessageList: (cb: BaseCallback, operationID: string, findMessageOptions: string) => void;
export const GetAdvancedHistoryMessageList: (cb: BaseCallback, operationID: string, getMessageOptions: string) => void;
export const GetAdvancedHistoryMessageListReverse: (cb: BaseCallback, operationID: string, getMessageOptions: string) => void;
export const RevokeMessage: (cb: BaseCallback, operationID: string, conversationID: string, clientMsgID: string) => void;
export const TypingStatusUpdate: (cb: BaseCallback, operationID: string, recvID: string, msgTip: string) => void;
export const MarkConversationMessageAsRead: (cb: BaseCallback, operationID: string, conversationID: string) => void;
export const MarkAllConversationMessageAsRead: (cb: BaseCallback, operationID: string) => void;
export const MarkMessagesAsReadByMsgID: (cb: BaseCallback, operationID: string, conversationID: string, clientMsgIDs: string) => void;
export const DeleteMessageFromLocalStorage: (cb: BaseCallback, operationID: string, conversationID: string, clientMsgID: string) => void;
export const DeleteMessage: (cb: BaseCallback, operationID: string, conversationID: string, clientMsgID: string) => void;
export const HideAllConversations: (cb: BaseCallback, operationID: string) => void;
export const DeleteAllMsgFromLocalAndSvr: (cb: BaseCallback, operationID: string) => void;
export const DeleteAllMsgFromLocal: (cb: BaseCallback, operationID: string) => void;
export const ClearConversationAndDeleteAllMsg: (cb: BaseCallback, operationID: string, conversationID: string) => void;
export const DeleteConversationAndDeleteAllMsg: (cb: BaseCallback, operationID: string, conversationID: string) => void;
export const InsertSingleMessageToLocalStorage: (cb: BaseCallback, operationID: string, message: string, recvID: string, sendID: string) => void;
export const InsertGroupMessageToLocalStorage: (cb: BaseCallback, operationID: string, message: string, groupID: string, sendID: string) => void;
export const SearchLocalMessages: (cb: BaseCallback, operationID: string, searchParam: string) => void;
export const SetMessageLocalEx: (cb: BaseCallback, operationID: string, conversationID: string, clientMsgID: string, localEx: string) => void;
export const SearchConversation: (cb: BaseCallback, operationID: string, searchParam: string) => void;
export const ChangeInputStates: (cb: BaseCallback, operationID: string, conversationID: string, focus: number) => void;
export const GetInputStates: (cb: BaseCallback, operationID: string, conversationID: string, userID: string) => void;
export const GetAtAllTag: (operationID: string) => string;
export const CreateAdvancedTextMessage: (operationID: string, text: string, messageEntityList: string) => string;
export const CreateTextAtMessage: (operationID: string, text: string, atUserList: string, atUsersInfo: string, message: string) => string;
export const CreateTextMessage: (operationID: string, text: string) => string;
export const CreateLocationMessage: (operationID: string, description: string, longitude: number, latitude: number) => string;
export const CreateCustomMessage: (operationID: string, data: string, extension: string, description: string) => string;
export const CreateQuoteMessage: (operationID: string, text: string, message: string) => string;
export const CreateAdvancedQuoteMessage: (operationID: string, text: string, message: string, messageEntityList: string) => string;
export const CreateCardMessage: (operationID: string, cardInfo: string) => string;
export const CreateVideoMessageFromFullPath: (operationID: string, videoFullPath: string, videoType: string, duration: number, snapshotFullPath: string) => string;
export const CreateImageMessageFromFullPath: (operationID: string, imageFullPath: string) => string;
export const CreateSoundMessageFromFullPath: (operationID: string, soundPath: string, duration: number) => string;
export const CreateFileMessageFromFullPath: (operationID: string, fileFullPath: string, fileName: string) => string;
export const CreateImageMessage: (operationID: string, imagePath: string) => string;
export const CreateImageMessageByURL: (operationID: string, sourcePath: string, sourcePicture: string, bigPicture: string, snapshotPicture: string) => string;
export const CreateSoundMessageByURL: (operationID: string, soundBaseInfo: string) => string;
export const CreateSoundMessage: (operationID: string, soundPath: string, duration: number) => string;
export const CreateVideoMessageByURL: (operationID: string, videoBaseInfo: string) => string;
export const CreateVideoMessage: (operationID: string, videoPath: string, videoType: string, duration: number, snapshotPath: string) => string;
export const CreateFileMessageByURL: (operationID: string, fileBaseInfo: string) => string;
export const CreateFileMessage: (operationID: string, filePath: string, fileName: string) => string;
export const CreateMergerMessage: (operationID: string, messageList: string, title: string, summaryList: string) => string;
export const CreateFaceMessage: (operationID: string, index: number, data: string) => string;
export const CreateForwardMessage: (operationID: string, m: string) => string;
export const GetConversationIDBySessionType: (operationID: string, sourceID: string, sessionType: number) => string;

export const CreateGroup: (cb: BaseCallback, operationID: string, groupReqInfo: string) => void;
export const JoinGroup: (cb: BaseCallback, operationID: string, groupID: string, reqMsg: string, joinSource: number, ex: string) => void;
export const QuitGroup: (cb: BaseCallback, operationID: string, groupID: string) => void;
export const DismissGroup: (cb: BaseCallback, operationID: string, groupID: string) => void;
export const ChangeGroupMute: (cb: BaseCallback, operationID: string, groupID: string, isMute: number) => void;
export const ChangeGroupMemberMute: (cb: BaseCallback, operationID: string, groupID: string, userID: string, mutedSeconds: number) => void;
export const TransferGroupOwner: (cb: BaseCallback, operationID: string, groupID: string, newOwnerUserID: string) => void;
export const KickGroupMember: (cb: BaseCallback, operationID: string, groupID: string, reason: string, userIDList: string) => void;
export const SetGroupInfo: (cb: BaseCallback, operationID: string, groupInfo: string) => void;
export const SetGroupMemberInfo: (cb: BaseCallback, operationID: string, groupMemberInfo: string) => void;
export const GetJoinedGroupList: (cb: BaseCallback, operationID: string) => void;
export const GetJoinedGroupListPage: (cb: BaseCallback, operationID: string, offset: number, count: number) => void;
export const GetSpecifiedGroupsInfo: (cb: BaseCallback, operationID: string, groupIDList: string) => void;
export const SearchGroups: (cb: BaseCallback, operationID: string, searchParam: string) => void;
export const GetGroupMemberOwnerAndAdmin: (cb: BaseCallback, operationID: string, groupID: string) => void;
export const GetGroupMemberListByJoinTimeFilter: (cb: BaseCallback, operationID: string, groupID: string, offset: number, count: number, joinTimeBegin: number, joinTimeEnd: number, filterUserIDList: string) => void;
export const GetSpecifiedGroupMembersInfo: (cb: BaseCallback, operationID: string, groupID: string, userIDList: string) => void;
export const GetGroupMemberList: (cb: BaseCallback, operationID: string, groupID: string, filter: number, offset: number, count: number) => void;
export const GetGroupApplicationListAsRecipient: (cb: BaseCallback, operationID: string, req: string) => void;
export const GetGroupApplicationListAsApplicant: (cb: BaseCallback, operationID: string, req: string) => void;
export const SearchGroupMembers: (cb: BaseCallback, operationID: string, searchParam: string) => void;
export const IsJoinGroup: (cb: BaseCallback, operationID: string, groupID: string) => void;
export const GetUsersInGroup: (cb: BaseCallback, operationID: string, groupID: string, userIDList: string) => void;
export const InviteUserToGroup: (cb: BaseCallback, operationID: string, groupID: string, reason: string, userIDList: string) => void;
export const AcceptGroupApplication: (cb: BaseCallback, operationID: string, groupID: string, fromUserID: string, handleMsg: string) => void;
export const RefuseGroupApplication: (cb: BaseCallback, operationID: string, groupID: string, fromUserID: string, handleMsg: string) => void;
export const CheckLocalGroupFullSync: (cb: BaseCallback, operationID: string) => void;
export const CheckGroupMemberFullSync: (cb: BaseCallback, operationID: string, groupID: string) => void;
export const GetGroupApplicationUnhandledCount: (cb: BaseCallback, operationID: string, req: string) => void;

export const InitSDK: (listener: ConnListener, operationID: string, config: string) => number;
export const UnInitSDK: (operationID: string) => void;
export const GetSdkVersion: () => string;
export const GetLoginUserID: () => string;
export const GetLoginStatus: (operationID: string) => number;
export const Login: (cb: BaseCallback, operationID: string, userID: string, token: string) => void;
export const Logout: (cb: BaseCallback, operationID: string) => void;
export const SetAppBackgroundStatus: (cb: BaseCallback, operationID: string, isBackground: number) => void;
export const NetworkStatusChanged: (cb: BaseCallback, operationID: string) => void;
export const SetGroupListener: (listener: GroupListener) => void;
export const SetConversationListener: (listener: ConversationListener) => void;
export const SetAdvancedMsgListener: (listener: AdvancedMsgListener) => void;
export const SetUserListener: (listener: UserListener) => void;
export const SetFriendListener: (listener: FriendshipListener) => void;
export const SetCustomBusinessListener: (listener: CustomBusinessListener) => void;
export const SetMessageKvInfoListener: (listener: MessageKvInfoListener) => void;
export const SubscribeUsersStatus: (cb: BaseCallback, operationID: string, userIDs: string) => void;
export const UnsubscribeUsersStatus: (cb: BaseCallback, operationID: string, userIDs: string) => void;
export const GetSubscribeUsersStatus: (cb: BaseCallback, operationID: string) => void;
export const GetUserStatus: (cb: BaseCallback, operationID: string, userIDs: string) => void;
export const GetSpecifiedFriendsInfo: (cb: BaseCallback, operationID: string, userIDList: string, filterBlack: number) => void;
export const GetFriendList: (cb: BaseCallback, operationID: string, filterBlack: number) => void;
export const GetFriendListPage: (cb: BaseCallback, operationID: string, offset: number, count: number, filterBlack: number) => void;
export const SearchFriends: (cb: BaseCallback, operationID: string, searchParam: string) => void;
export const CheckFriend: (cb: BaseCallback, operationID: string, userIDList: string) => void;
export const AddFriend: (cb: BaseCallback, operationID: string, userIDReqMsg: string) => void;
export const UpdateFriends: (cb: BaseCallback, operationID: string, req: string) => void;
export const DeleteFriend: (cb: BaseCallback, operationID: string, friendUserID: string) => void;
export const GetFriendApplicationListAsRecipient: (cb: BaseCallback, operationID: string, req: string) => void;
export const GetFriendApplicationListAsApplicant: (cb: BaseCallback, operationID: string, req: string) => void;
export const AcceptFriendApplication: (cb: BaseCallback, operationID: string, userIDHandleMsg: string) => void;
export const RefuseFriendApplication: (cb: BaseCallback, operationID: string, userIDHandleMsg: string) => void;
export const AddBlack: (cb: BaseCallback, operationID: string, blackUserID: string, ex: string) => void;
export const GetBlackList: (cb: BaseCallback, operationID: string) => void;
export const RemoveBlack: (cb: BaseCallback, operationID: string, removeUserID: string) => void;
export const GetFriendApplicationUnhandledCount: (cb: BaseCallback, operationID: string, req: string) => void;
export const UpdateFcmToken: (cb: BaseCallback, operationID: string, fcmToken: string, expireTime: number) => void;
export const SetAppBadge: (cb: BaseCallback, operationID: string, appUnreadCount: number) => void;
export const UploadLogs: (cb: BaseCallback, operationID: string, line: number, ex: string, progress: UploadLogProgressCallback) => void;
export const Logs: (cb: BaseCallback, operationID: string, logLevel: number, file: string, line: number, msgs: string, err: string, keyAndValue: string) => void;
export const UploadFile: (cb: BaseCallback, operationID: string, req: string, progress: UploadFileCallback) => void;
export const GetUsersInfo: (cb: BaseCallback, operationID: string, userIDs: string) => void;
export const SetSelfInfo: (cb: BaseCallback, operationID: string, userInfo: string) => void;
export const GetSelfUserInfo: (cb: BaseCallback, operationID: string) => void;
export const GetUserClientConfig: (cb: BaseCallback, operationID: string) => void;
export const NewLoginMgr: () => number;
export const FreeLoginMgr: (id: number) => void;
export const CheckResourceLoad: (id: number, funcName: string) => ErrMsg;
